package com.watson.todolist.database;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.watson.todolist.constants.DatabaseConstants;

/**
 * This class handles the table set up for the TagItemTable.
 * 
 * @author Donnie Ward
 * 
 * @since 1.0
 */
public class TagItemTable {
	/**
	 * Logger tag
	 */
	private static String TAG = "TagItemTable Class";
	/**
	 * SQL statement to create tag item table
	 */
	private static String CREATE_TAG_ITEM_TABLE = "CREATE TABLE "
			+ DatabaseConstants.TAG_ITEM_TABLE_NAME + " ("
			+ DatabaseConstants.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
			+ DatabaseConstants.TIME_STAMP
			+ " DATETIME DEFAULT CURRENT_TIMESTAMP, "
			+ DatabaseConstants.TAG_ITEM_TABLE_USER_ID + " INTEGER NOT NULL, "
			+ DatabaseConstants.TAG_ITEM_TABLE_TAG_NAME + " TEXT NOT NULL);";

	/**
	 * Creates tag item table within database
	 * 
	 * @param database
	 *            - database to perform operations on
	 */
	public static void onCreate(SQLiteDatabase database) {
		database.execSQL(CREATE_TAG_ITEM_TABLE);
		Log.d(TAG, "Tag item table created.");
	}

	/**
	 * Upgrades tag item table within database
	 * 
	 * @param database
	 *            - database to perform operations on
	 * @param oldVersion
	 *            - previous version of table before upgrading
	 * @param newVersion
	 *            - subsequent version of table after upgrading
	 */
	public static void onUpgrade(SQLiteDatabase database, int oldVersion,
			int newVersion) {
		database.execSQL("DROP TABLE IF EXISTS "
				+ DatabaseConstants.TAG_ITEM_TABLE_NAME);
		onCreate(database);
		Log.d(TAG, "Tag item table upgraded.");
	}
}
